# ------------------------------------------
# 准备工作
# ------------------------------------------

setwd("/Users/eimei/Documents/Rdata/")  # 设定工作空间
data <- read.csv("HRdata.csv")  # 读取数据

# ------------------------------------------
# 以列方式删除数据框中的变量
# ------------------------------------------

str(data)
newdata <- data[c(-1, -2)]
str(newdata)

# ------------------------------------------
# 以变量名的形式删除数据框中的变量
# ------------------------------------------

newvars <- names(data) %in% c("EmployeeNumber", "Age")
newdata <- data[!newvars]

str(newdata)

names(data)
names(data) %in% c("EmployeeNumber", "Age")
!newvars

# ------------------------------------------
# 任务一
# ------------------------------------------

newdata <- data[c("EmployeeNumber", "Age", "Department",
                  "EnvironmentSatisfaction", "JobSatisfaction",
                  "MonthlyIncome", "RelationshipSatisfaction")]
head(newdata)
str(newdata)

# ------------------------------------------
# 任务二
# ------------------------------------------

newvars <- names (newdata) %in% c ("Age", "Department", "MonthlyIncome")
newdata <- newdata[!newvars]

head(newdata)